package kz.pdt12.hw.tests;

import kz.pdt12.hw.data.GroupData;
import kz.pdt12.hw.utils.SortedListOf;
import org.testng.annotations.Test;

import java.util.Random;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
 * Created with IntelliJ IDEA.
 * User: raimbek
 * Date: 09.03.13
 * Time: 23:38
 */
public class GroupRemovalTests extends TestBase {

    @Test
    public void deleteSomeGroup() {
        // save old state
        SortedListOf<GroupData> oldList = app.getGroupHelper().getUiGroups();

        Random random = new Random();
        int index = random.nextInt(oldList.size() - 1);

        // actions
        app.getGroupHelper().deleteGroup(index);

        // save new state
        SortedListOf<GroupData> newList = app.getGroupHelper().getUiGroups();

        //compare states
        assertThat(newList, equalTo(oldList.without(index)));

        if (app.getPropertyKey("check.db").equals("yes")) {
            assertThat(app.getModel().getGroups(), equalTo(app.getHibernateHelper().listGroups()));
        }
        if (app.getPropertyKey("check.ui").equals("yes")) {
            assertThat(app.getModel().getGroups(), equalTo(app.getGroupHelper().getUiGroups()));
        }
    }
}
